package study.web.security;

import javax.annotation.Resource;

import lombok.extern.slf4j.Slf4j;

import org.springframework.social.connect.Connection;
import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.NativeWebRequest;

/**
 * Spring Security를 사용한 Sign In. 인증후 사용자를 세션에 넣는다.
 *
 * @author Barney Kim
 */
@Slf4j
@Service
public class SpringSecuritySignInAdapter implements SignInAdapter {

	@Resource(name = "securitySupport")
	private SecuritySupport securitySupport;

	@Override
	public String signIn(String username, Connection<?> connection,
			NativeWebRequest request) {
		log.debug("signIn called");
		securitySupport.setAuthentication(username);
		securitySupport.setSessionUser(request, username);
		return null;
	}
}
